package com.yishan.gulimall.springsecurity.config;

import javafx.beans.WeakListener;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.CorsRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

/**
 * 跨域配置
 */
@Configuration
public class CorsConfig implements WebMvcConfigurer {
    @Override
    public void addCorsMappings(CorsRegistry registry) {
        // 允许跨域访问
        registry.addMapping("/**")
                // 允许所有域名跨域
                .allowedOrigins("*")
                // 允许所有请求方法跨域
                .allowedMethods("GET", "POST", "PUT", "DELETE")
                // 允许所有请求头跨域
                .allowedHeaders("*")
                // 允许携带cookie
                .allowCredentials(true)
                // 设置预检请求的有效期
                .maxAge(3600);
    }
}
